/*   1:    */ package com.atomikos.beans;
/*   2:    */ 
/*   3:    */ import java.awt.Component;
/*   4:    */ import java.awt.GridBagConstraints;
/*   5:    */ import java.awt.GridBagLayout;
/*   6:    */ import java.awt.Toolkit;
/*   7:    */ import java.awt.event.ActionEvent;
/*   8:    */ import java.awt.event.KeyAdapter;
/*   9:    */ import java.awt.event.KeyEvent;
/*  10:    */ import java.beans.PropertyEditor;
/*  11:    */ import javax.swing.JLabel;
/*  12:    */ import javax.swing.JPanel;
/*  13:    */ import javax.swing.JTextField;
/*  14:    */ import javax.swing.event.CaretEvent;
/*  15:    */ import javax.swing.event.CaretListener;
/*  16:    */ 
/*  17:    */ public class TextFieldComponent
/*  18:    */   extends AbstractPropertyEditorComponent
/*  19:    */   implements CaretListener
/*  20:    */ {
/*  21:    */   private JTextField text_;
/*  22:    */   private JPanel panel_;
/*  23:    */   private Property property_;
/*  24:    */   private boolean decimal_;
/*  25:    */   
/*  26:    */   public TextFieldComponent(Property property)
/*  27:    */     throws PropertyException
/*  28:    */   {
/*  29: 65 */     this.property_ = property;
/*  30: 66 */     this.panel_ = new JPanel();
/*  31: 67 */     GridBagLayout layout = new GridBagLayout();
/*  32: 68 */     this.panel_.setLayout(layout);
/*  33: 69 */     GridBagConstraints c = new GridBagConstraints();
/*  34: 70 */     c.fill = 2;
/*  35: 71 */     JLabel label = new JLabel(property.getName());
/*  36: 72 */     this.text_ = new JTextField(10);
/*  37: 73 */     layout.setConstraints(this.text_, c);
/*  38: 74 */     this.text_.setToolTipText(property.getDescription());
/*  39: 75 */     this.panel_.add(this.text_);
/*  40: 76 */     this.text_.addCaretListener(this);
/*  41:    */   }
/*  42:    */   
/*  43:    */   public TextFieldComponent(Property property, boolean allowsDecimalPoint)
/*  44:    */     throws PropertyException
/*  45:    */   {
/*  46: 82 */     this(property);
/*  47: 83 */     this.decimal_ = allowsDecimalPoint;
/*  48: 84 */     this.text_.addKeyListener(new KeyAdapter()
/*  49:    */     {
/*  50:    */       public void keyTyped(KeyEvent e)
/*  51:    */       {
/*  52: 86 */         char c = e.getKeyChar();
/*  53: 87 */         if ((!Character.isDigit(c)) && (c != '\b') && (c != '') && ((c != '.') || (!TextFieldComponent.this.decimal_)))
/*  54:    */         {
/*  55: 91 */           e.consume();
/*  56: 92 */           TextFieldComponent.this.panel_.getToolkit().beep();
/*  57:    */         }
/*  58:    */       }
/*  59:    */     });
/*  60:    */   }
/*  61:    */   
/*  62:    */   public Component getComponent()
/*  63:    */   {
/*  64:    */     try
/*  65:    */     {
/*  66:105 */       this.text_.setText(this.property_.getEditor().getStringValue());
/*  67:    */     }
/*  68:    */     catch (PropertyException e) {}
/*  69:109 */     return this.panel_;
/*  70:    */   }
/*  71:    */   
/*  72:    */   public void actionPerformed(ActionEvent e)
/*  73:    */   {
/*  74:114 */     Class wrapperClass = PrimitiveClasses.getWrapperClass(this.property_.getType());
/*  75:    */     try
/*  76:    */     {
/*  77:117 */       if (wrapperClass == null)
/*  78:    */       {
/*  79:118 */         getPropertyEditor().setAsText(this.text_.getText());
/*  80:    */       }
/*  81:    */       else
/*  82:    */       {
/*  83:122 */         Object value = PrimitiveClasses.createWrapperObject(this.text_.getText(), this.property_.getType());
/*  84:    */         
/*  85:124 */         getPropertyEditor().setValue(value);
/*  86:    */       }
/*  87:    */     }
/*  88:    */     catch (Exception err)
/*  89:    */     {
/*  90:130 */       err.printStackTrace();
/*  91:    */     }
/*  92:    */   }
/*  93:    */   
/*  94:    */   public void caretUpdate(CaretEvent e)
/*  95:    */   {
/*  96:136 */     if ((this.text_.getText() == null) || (this.text_.getText().equals(""))) {
/*  97:136 */       return;
/*  98:    */     }
/*  99:138 */     Class wrapperClass = PrimitiveClasses.getWrapperClass(this.property_.getType());
/* 100:    */     try
/* 101:    */     {
/* 102:141 */       if (wrapperClass == null)
/* 103:    */       {
/* 104:142 */         getPropertyEditor().setAsText(this.text_.getText());
/* 105:    */       }
/* 106:    */       else
/* 107:    */       {
/* 108:145 */         Object value = PrimitiveClasses.createWrapperObject(this.text_.getText(), this.property_.getType());
/* 109:    */         
/* 110:147 */         getPropertyEditor().setValue(value);
/* 111:    */       }
/* 112:    */     }
/* 113:    */     catch (Exception err)
/* 114:    */     {
/* 115:153 */       err.printStackTrace();
/* 116:    */     }
/* 117:    */   }
/* 118:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.beans.TextFieldComponent
 * JD-Core Version:    0.7.0.1
 */